public class DemoAbstractFactory {

    public static void main(String[] args) {
        IDatabaseUtil iDatabaseUtil = new MysqlDatabase();
        //获取连接
        IConnectipn iConnectipn = iDatabaseUtil.getConnection();
        iConnectipn.connection();
        //执行sql
        ICommand iCommand = iDatabaseUtil.getCommond();
        iCommand.command();
    }
}

//● 变化:   mysql ,oracle,....
//● 共性:  connection(连接)  ,  command(执行sql),close(关闭)

interface IConnectipn {
    // 数据库连接
    void connection();
}

interface ICommand {
    // 执行方法
    void command();
}

interface IDatabaseUtil {
    IConnectipn getConnection();

    ICommand getCommond();
}

/*------mysql------*/
class MysqlConnect implements IConnectipn {

    @Override
    public void connection() {
        System.out.println("mysql进行链接");
    }
}

class MysqlCommond implements ICommand {

    @Override
    public void command() {
        System.out.println("mysql进行执行sql");
    }
}

class MysqlDatabase implements IDatabaseUtil {

    @Override
    public IConnectipn getConnection() {
        return new MysqlConnect();
    }

    @Override
    public ICommand getCommond() {
        return new MysqlCommond();
    }
}